<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Myclass {
	
	private static $url = 'http://houtai.5664wan.com/isdk/';
	
	public function get_onlineip() {
	
		$onlineip = '';
	
		if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {
	
			$onlineip = getenv('HTTP_CLIENT_IP');
	
		} elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {
	
			$onlineip = getenv('HTTP_X_FORWARDED_FOR');
	
		} elseif(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {
	
			$onlineip = getenv('REMOTE_ADDR');
	
		} elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {
	
			$onlineip = $_SERVER['REMOTE_ADDR'];
	
		}
	
		return $onlineip;
	
	}
	
	/*
	 * 获取密钥
	 * */
	public function get_key($siteid = ''){
	
		$siteid = 'siteid='.$siteid;
	
		return $this->vpost(self::$url."site_encrypt",$siteid);
	
	}
	
	/*
	 * 数据传输
	* */
	public function vpost($url = '',$data = '',&$httpCode = ''){
	
		$curl = curl_init();
	
		curl_setopt($curl, CURLOPT_URL, $url);
	
		curl_setopt($curl, CURLOPT_POST, 1);
	
		curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
	
		curl_setopt($curl, CURLOPT_TIMEOUT, 30);
	
		curl_setopt($curl, CURLOPT_HEADER, 0);
	
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
	
		$tmpInfo = curl_exec($curl);
		$httpCode = curl_getinfo($curl);
		
		curl_close($curl);	
	
		return $tmpInfo;
	}

    public function randomkeys($length=8)
    {
     $pattern='1234567890abcdefghijklmnopqrstuvwxyz';
     $key = '';
     for($i=0;$i<$length;$i++)
     {
       $key .= $pattern{mt_rand(0,15)};    
     }
     return $key;
    }
	
	public function v_post($url, $data){
		$ch = curl_init();
		curl_setopt($ch,CURLOPT_URL,$url);
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
		return curl_exec($ch);
	}
	
	public function SendMail($subject,$message, $conf){
		//配置邮箱参数
		$config['protocol']= 'smtp';
		
		$config['smtp_host'] = $conf->smtpserver;  
		$config['smtp_user'] = $conf->smtpuser;  
		$config['smtp_pass'] = $conf->smtppassword;  
		$config['smtp_port'] = '465';
		  
		$config['charset'] = 'utf-8';  
		$config['wordwrap'] = TRUE;  
		$config['mailtype'] = 'html'; 
		$config['newline'] = "\r\n";
		$config['crlf'] = "\r\n";  
		
		$sdk =& get_instance();
		$sdk->load->library('email',$config); 
		
		//开始发送邮件
		$sdk->email->clear();
	
		$sdk->email->to($conf->email);
		$sdk->email->from($conf->smtpuser);
		$sdk->email->subject($subject);
		$sdk->email->message($message);
		$sdk->email->send();

	}
	
	public function get_payinfo($msg = array()){
	
		$data = array(
				'cmd' => '_xclick',
				'item_name' => 'product',
				'item_number' => $msg['orderid'],
				'currency_code' => 'USD',
				'shipping' => $msg['shippingfee'],
				'tax_rate' => 0,
				'amount' => $msg['amount'],
				'business' => 'BKUVNHGAL2RPN',
				'lc' => 'C2',
				'button_subtype' => 'services',
				'bn' => 'PP-BuyNowBF:btn_buynowCC_LG.gif:NonHosted',
				'return_url' => site_url().'user_mag',
				'notify_url' => site_url().'return_page'
		);
	
		return $data;
			
	}
	
	public function pagination($curr_page='',$total_page='',$url='',$getname='',$getnum=''){
		
		if(!$total_page||!$curr_page||!$url) return false;
		
		$getinfo = $getname&&$getnum?'?'.$getname.'='.$getnum:'';
		
		$total_page = ceil($total_page);
		
		$pagination = '';
		
		if($curr_page>1){
			
			$pagination .= '<a href="'.$url.'/'.($curr_page-1).$getinfo.'" rel="nofollow" class="pre">&laquo;</a>';
		}
		
		if($total_page>8){
			
			if($curr_page>=4){
				
				$pagination .= '<a href="'.$url.'/1'.$getinfo.'">1</a>';
					
				$pagination .= '<a href="#">...</a>';
					
				if($curr_page+2<$total_page){
				
					for ($i=$curr_page-3;$i<=$curr_page+3;$i++){
							
						if ($i == $curr_page) {
								
							$pagination .= '<span><a href="#">'.$i.'</a><span>';
								
							continue;
								
						}
				
						$pagination .= '<a href="'.$url.'/'.$i.$getinfo.'">'.$i.'</a>';
							
					}
				
					$pagination .= '<a href="#">...</a>';
				
					$pagination .= '<a href="'.$url.'/'.$total_page.$getinfo.'">'.$total_page.'</a>';
				
				}else{
				
					for ($i=$curr_page-2;$i<=$total_page;$i++){
							
						if ($i == $curr_page) {
								
							$pagination .= '<span><a href="#">'.$i.'</a><span>';
								
							continue;
								
						}
							
						$pagination .= '<a href="'.$url.'/'.$i.$getinfo.'">'.$i.'</a>';
							
					}
				
				}
				
				
			}else{

				for ($i=1;$i<=$curr_page+2;$i++){
				
					if ($i == $curr_page) {
							
						$pagination .= '<span><a href="#">'.$i.'</a><span>';
							
						continue;
				
					}
						
					$pagination .= '<a href="'.$url.'/'.$i.$getinfo.'">'.$i.'</a>';
				
				}
					
				$pagination .= '<a href="#">...</a>';
					
				$pagination .= '<a href="'.$url.'/'.$total_page.$getinfo.'">'.$total_page.'</a>';
				
				
			}
		}else{
			
			for($i=1;$i<=$total_page;$i++){
				
				if($i == $curr_page){
					
					$pagination .= '<a href="#">'.$i.'</a>';
					
					continue;
				}
				
				$pagination .= '<a href="'.$url.'/'.$i.$getinfo.'">'.$i.'</a>';
				
			}
		
		}
		
		if($curr_page<$total_page){
			$pagination .= '<a href="'.$url.'/'.($curr_page+1).$getinfo.'" rel="nofollow" class="next">&raquo;</a>';				
		}
		
		$pagination .= '';
		
		return $pagination;
		
	}
	
	
	
	
}